/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.ainlolcat.ainscience.column;

import org.ainlolcat.ainscience.matrix.MatrixFileParser;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author ain
 */
public class ColumnImpl extends AbstractColumn {

    public ColumnImpl(String name, Integer type, String axis, List<String> values){
        this.name = name;
        this.axis = axis;
        this.type = type;
        this.values = values;
    }

    public ColumnImpl(String name, Integer type, String axis){
        this.name = name;
        this.axis = axis;
        this.type = type;
    }

    public ColumnImpl(List<String> values){
        this.values = values;
    }

    public ColumnImpl(String name){
        values = new ArrayList<String>();
        this.name = name;
    }

    public Column clone(){
        String clonename = null;
        String cloneaxis = null;
        Integer clonetype = null;

        if (getName()!=null){
            clonename = new String(getName());
        }
        if (getAxis()!=null){
            cloneaxis = new String(getAxis());
        }
        if (getType()!=null){
            clonetype = new Integer(type);
        } else {
            clonetype = new Integer(MatrixFileParser.MATRIX_DELIMETER_TYPE_STRING);
        }

        List clonevalues = new ArrayList();
        for (int i=0;i<size();i++){
            if (clonetype.equals(MatrixFileParser.MATRIX_DELIMETER_TYPE_DOUBLE)){
                clonevalues.add(getValue(i));
            } else if (clonetype.equals(MatrixFileParser.MATRIX_DELIMETER_TYPE_INTEGER)){
                clonevalues.add(getValue(i));
            } else if (clonetype.equals(MatrixFileParser.MATRIX_DELIMETER_TYPE_STRING)){
                clonevalues.add(getValue(i));
            } else if (clonetype.equals(MatrixFileParser.MATRIX_DELIMETER_TYPE_BOOLEAN)){
                clonevalues.add(getValue(i));
            }
        }

        Column clone = new ColumnImpl(clonevalues);
        if (clonename!=null) clone.setName(clonename);
        if (cloneaxis!=null) clone.setAxis(cloneaxis);
        if (clonetype!=null) clone.setType(clonetype);
        return clone;
    }
}
